﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sekretar.Repository;
using System.Linq;

namespace Sekretar
{
    public partial class DrzavaRecView : Common.Forms.RecView
    {
        RDrzava rDrzava = new RDrzava();
        int id;
        public int ID;

        public DrzavaRecView(int id)
        {
            InitializeComponent();
            this.id = id;
        }

        private void DrzavaRecView_Load(object sender, EventArgs e)
        {
            if (id == 0)
                DrzavaBindingSource.DataSource = rDrzava.Nov();
            else
                DrzavaBindingSource.DataSource = rDrzava.Izmeni(this.id);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                DrzavaBindingSource.EndEdit();
                int id = rDrzava.Snimi((DataLayer.Drzava)DrzavaBindingSource.Current);
                this.Index = rDrzava.VratiSve().ToList().FindIndex(c => c.DrzavaId == id);
                this.ID = ((DataLayer.Drzava)DrzavaBindingSource.Current).DrzavaId;
            }
            catch (Exception ex)
            {
                Common.Tools.MessageError.Show(ex.Message);
                this.DialogResult = DialogResult.None;
            }
        }
    }
}
